import vim
import glob
import os

is_gui_running = (vim.eval('has("gui_running")') == '1')

def edit_file( file ):
	vim.command('edit %s' % file)

def get_curdir():
	return vim.eval('getcwd()')

def load_session( file ):
	vim.command('bufdo bdelete!')
	vim.command('source $HOME/.vim/sessions/%s.vim' % file)

def save_session( file ):
	vim.command('mksession! $HOME/.vim/sessions/%s.vim' % file)

def get_sessions():
	session_files = []
	s = os.path.join(vim.eval('$HOME'), '.vim', 'sessions', '*.vim')
	for s in glob.glob(s):
		s = os.path.basename(s)
		s, e = os.path.splitext(s)
		session_files.append( s )
	return session_files	

def input( prompt ):
	return vim.eval('input("%s:")' % prompt)

def input_list( prompt, options ):
	s = '"%s:"' % prompt
	i = 1 
	for o in options:
		s += ',"%i. %s"' % (i, o.replace('\\','/'))
		i += 1
	r =  int(vim.eval('inputlist([%s])' % s))
	if (r > 0) and (r <= len(options) ):
		return r - 1
	return -1

def set_error_file( file ):
	vim.command('cfile %s' % file)	

